<html>
<head>
    <title>注册</title>
    <meta charset="UTF-8"/>
    <meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0"/>


    <script src="/js/common.js"></script>
    <style type="text/css">
        .container{
            background-color: transparent;
        }
    </style>
</head>
<body>
<nav class="navbar navbar-default">
    <div class="container-fluid">
        <div class="navbar-header">
            <a class="navbar-brand" href="#"></a>
        </div>

        <div class="collapse navbar-collapse">
        </div>
    </div>
</nav>
<div class="container"  >
        <div class="" >
            <div class="shadow">
                <form action="#" id="registerForm" name="registerForm" onsubmit="return false">
                    <div class=" " id="register" >
                        <div><strong id="errorMsg"  style="color: red;margin-left: 18px;"></strong></div>
                        <div class="form-group">
                            <label for="userName">用户名：</label><input id="userName" class="form-control" placeholder="不小于8位字母或数字" name="userName"  maxlength="20" type="text" onblur="validateUserName()"required onkeydown="if(event.keyCode==32) return false">
                            <span class="error-account" id="error-userName"></span>
                        </div>
                        <div class="form-group"><label for="passWord">密码：</label><input id="password" placeholder="不小于6位字母或数字" class="form-control" name="password"  maxlength="10" type="password" required onkeydown="if(event.keyCode==32) return false"></div>
                    </div>
                    <a href="/">有账号？去登录</a>
                        <div class="form-group"><a  class="btn btn-primary  btn-block" onclick="registerUser()">注册</a></div>
                        <br>

                </form>

            </div>

        </div>

</div>
<script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>

<script src="/js/dialog.min.js"></script>
<script src="/js/zepto.min.js"></script>
<script type="text/javascript">

    function registerUser(){
        var userName=$('#userName').val();
        var password=$('#password').val();
            $.ajax({
                cache: true,
                type: "POST",
                url:"/user/register",
                data:$('#registerForm').serialize(),// 你的formid
                async: false,
                error: function(request) {
                   alert("连接失败")
                },
                success: function(data) {
                    if (data.code==200){
                       alert("注册成功，点击确认两秒后跳转到登录页面");
                        setTimeout(function () {
                            location.href="/";
                        },1500)
                    }else{
                        alert(data.message);
                    }

                }
            });


    }

</script>
</body>

</html>
